package com.qfedu.edu.pojo;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author xiaobobo
 * @title: SecurityUser
 * @projectName CD-Java-FY-2401-Springboot-Parent
 * @description: TODO
 * @date 2024/9/12  10:25
 */
public class SecurityUser implements UserDetails {

    //用户对象
    private User user;

    //角色和权限的集合
    private List<String> rolesAndPerms;

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public List<String> getRolesAndPerms() {
        return rolesAndPerms;
    }

    public void setRolesAndPerms(List<String> rolesAndPerms) {
        this.rolesAndPerms = rolesAndPerms;
    }

    /**
     * 返回所有的权限信息
     *
     * @return
     */
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        List<GrantedAuthority> lists=new ArrayList<>();
        for (int i = 0; i <rolesAndPerms.size() ; i++) {
           lists.add(new SimpleGrantedAuthority(rolesAndPerms.get(i)));
        }
        return lists;
    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        //没过期
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        //账户是否没有被锁定
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        //证书是否已经过期
        return true;
    }

    @Override
    public boolean isEnabled() {
        //这个账户是否能用
        return true;
    }
}
